package sketch.generator;

import java.util.ArrayList;
import java.util.List;

import sketch.generator.examples.PermutationSequentialValueGenerator;

public class PermutationValueGenerator<T> extends ValueGenerator<T> {

	private List<T> values = new ArrayList<T>();
	
	private final PermutationSequentialValueGenerator<T> innerGenerator;
	
	@SuppressWarnings("unchecked")
	public PermutationValueGenerator(T... values) {
		super();
		add(values);
		IGenerator<T>[] generators = new IGenerator[values.length];
		for(int i = 0; i < values.length; i++) {
			ChainValueGenerator<T> chain = new ChainValueGenerator<T>(values);
			generators[i] = chain;
		}
		innerGenerator = new PermutationSequentialValueGenerator<T>(generators);
	}
	
	public void add(T value) {
		values.add(value);
	}
	
	public void add(T...values) {
		for(T value : values) {
			add(value);
		}
	}
	
	public boolean hasNextPermutation() {
		return this.innerGenerator.hasNext();
	}
	
	public List<T> nextPermutation() {
		return this.innerGenerator.next().getValues();
	}
	
	@Override
	public T composeData() {
		throw new UnsupportedOperationException("Compose data not implemented" +
				" in PermutationValueGen");
	}

	@Override
	protected T generateNext() {
		throw new UnsupportedOperationException("GenerateNext() not implemented" +
				" in PermutationValueGen");
	}

	@Override
	public boolean hasNext() {
//		throw new UnsupportedOperationException("HasNext() not implemented" +
//				" in PermutationValueGen");
		return this.hasNextPermutation();
	}

	@Override
	public List<T> nextWrappedValue() {
		List<T> listT = this.nextPermutation();
		return listT;
	}
}
